home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-09-09 | 8.8 KB | 275 lines | [TEXT/CWIE] |
- // An about box window
- //
- // David Hayward
- // Developer Technical Support
- // AppleLink: DEVSUPPORT
- //
- // Copyrite 1995, Apple Computer,Inc
- //
- // This file contains the handlers procs for an about box window.
- //
- // 12/13/94 david first cut
-
-
- #include <Types.h>
- #include <Files.h>
- #include <QDOffScreen.h>
- #include <Resources.h>
- #include <TextEdit.h>
-
- #include "appGlobals.h"
- #include "appMain.h"
- #include "appMenus.h"
-
- #include "win.h"
- #include "winTables.h"
- #include "winAbout.h"
-
- #include "resourceUtils.h"
-
-
- /**\
- |**| ==============================================================================
- |**| PRIVATE DEFINES
- |**| ==============================================================================
- \**/
- #define rAboutBoxStringID 2000 // 'STR ' resource id
- #define rAboutDocWindID 2000 // 'WIND' resource id
-
-
- /**\
- |**| ==============================================================================
- |**| PRIVATE FUNCTION PROTOTYPES
- |**| ==============================================================================
- \**/
- OSErr DoCreateAboutWindow ( winHandle win ) ;
-
-
- /**\
- |**| ==============================================================================
- |**| PUBLIC FUNCTIONS
- |**| ==============================================================================
- \**/
-
-
- /*------------------------------------------------------------------------------*\
- winUpdateAbout
- *------------------------------------------------------------------------------*
- This is a UpdateProcPtr for the About window.
- It handles all drawing into the window.
- For the About window, this means that this routine is responible for
- drawing the text into the About box.
- This ProcPtr is envoked by CallWinUpdateProc() which is called by:
- DoUpdateEvent() which dispaches update events.
- \*------------------------------------------------------------------------------*/
- void winUpdateAbout ( winHandle win, EventRecord *e )
- {
- long length ;
- Rect aboutRect ;
- Handle aboutText ;
- WindowRef window = (WindowRef)e->message;
- GrafPtr savedPort ;
-
- GetPort( &savedPort ) ;
- SetPort( (GrafPtr)window ) ;
-
- BeginUpdate( window ) ;
-
- aboutRect = GetRect( rAboutBoxStringID ) ;
-
- aboutText = GetResource( 'TEXT', rAboutBoxStringID ) ;
- HLock( aboutText ) ;
- length = GetHandleSize( aboutText ) ;
- TETextBox( *aboutText, length, &aboutRect, teCenter) ;
- HUnlock( aboutText ) ;
- ReleaseResource( aboutText ) ;
-
- // signal that we finished drawing
- EndUpdate( window ) ;
- SetPort( savedPort ) ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- winCloseAbout
- *------------------------------------------------------------------------------*
- This is a CloseProcPtr for the About window.
- All this does is call DisposeWinHandle()
- This ProcPtr is envoked by CallWinCloseProc() which is called by:
- app_aePDOC_handler() which handles PDOC AppleEvents,
- DoMouseDownEvent() which dispached click events (e.g. close box), and
- MenuProcPtrs which are called whenever menu events occur.
- \*------------------------------------------------------------------------------*/
- void winCloseAbout ( winHandle win )
- {
- DisposeWinHandle( win ) ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- winMenuAbout
- *------------------------------------------------------------------------------*
- This is a MenuProcPtr for the About window.
- This routine dispatches any menu commands that the window can handle
- to the appropriate function.
- For the About window, the only need menu command is File:Close
- This ProcPtr is envoked by CallWinMenuProc() which is called by:
- HandleMenuCommand() which dispatches all menu events.
- \*------------------------------------------------------------------------------*/
- void winMenuAbout ( winHandle win, long menuResult, Boolean *didit )
- {
- short menuID;
- short menuItem;
- winHandle frontWin;
-
- frontWin = GetFrontWindowWinHandle() ;
-
- if ( win == frontWin )
- {
- *didit = true ;
- menuID = HiWrd(menuResult) ;
- menuItem = LoWrd(menuResult) ;
- switch ( menuID )
- {
- default :
- *didit = false ;
- break ;
- }
- HiliteMenu(0) ; // Unhighlight whatever MenuSelect or MenuKey hilited
- }
- }
-
-
-
- /*------------------------------------------------------------------------------*\
- winUpdateMenusAbout
- *------------------------------------------------------------------------------*
- This is a UpdateMenusProcPtr for the About window.
- This routine enables any menu commands that the window can handle.
- For the About window, the only need menu command is File:Close
- This ProcPtr is envoked by CallWinUpdateMenusProc() which is called by:
- DoAppAdjustMenus() which enables menu commands.
- \*------------------------------------------------------------------------------*/
- void winUpdateMenusAbout ( winHandle win )
- {
- MenuHandle theMenu ;
- winHandle frontWin;
-
- frontWin = GetFrontWindowWinHandle() ;
-
- if ( win == frontWin )
- {
- // do the file menu
- theMenu = GetMenuHandle ( mFile ) ;
-
- EnableItem ( theMenu, kWholeMenu ) ;
- EnableItem ( theMenu, iClose ) ;
- }
- }
-
-
- /*------------------------------------------------------------------------------*\
- winAllocAbout
- *------------------------------------------------------------------------------*
- This is a winAllocAbout for the About window.
- This routine is responsible for filling in all the needed fields of the
- winHandle structure. This routine shouldn't be called directly.
- Instead, the code which needs to create a document of this type should
- call NewWinHandle(win,winAllocAbout) to envoke this function.
- This ProcPtr is envoked by NewWinHandle() which is called by:
- DoAboutBoxCommand() which handles the Apple:About menu command.
- \*------------------------------------------------------------------------------*/
- OSErr winAllocAbout ( winHandle win )
- {
- OSErr err = noErr ;
-
- // set the window type
- SetWinType( win, kAboutDocType ) ;
-
- // stuff winHandle fields
- SetWinUpdateProc ( win, (UpdateProcPtr) winUpdateAbout ) ;
- SetWinMenuProc ( win, (MenuProcPtr) winMenuAbout ) ;
- SetWinUpdateMenusProc ( win, (UpdateMenusProcPtr) winUpdateMenusAbout ) ;
- SetWinNewProc ( win, (NewProcPtr) winNewAbout ) ;
- SetWinCloseProc ( win, (CloseProcPtr) winCloseAbout ) ;
-
- return err ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- winNewAbout
- *------------------------------------------------------------------------------*
- This is a NewProcPtr for the About window.
- This routine is responsible for building a new About window after all the
- needed fields of the winHandle structure have been filled in by winAllocAbout.
- If an About window is already open, then this routine will bring it
- to the front instead of opening a second window.
- This routine shouldn't be called directly. Instead, the code which needs
- to create a document of this type should call NewWinHandle(win,winAllocAbout),
- and then CallWinNewProc(win) to envoke this function.
- This ProcPtr is envoked by CallWinNewProc() which is called by:
- DoAboutBoxCommand() which handles the Apple:About menu command.
- \*------------------------------------------------------------------------------*/
- OSErr winNewAbout ( winHandle win )
- {
- OSErr err = noErr ;
- winHandle existingDoc ;
-
- // see if we are already open
-
- if ( FindWinHandle( nil, kAboutDocType, nil, 1, 1, &existingDoc ) == 1 )
- {
- // bring it to the front
- SelectWindow( GetWinWindow(existingDoc) ) ;
- return kWasAlreadyOpen ;
- }
-
- err = DoCreateAboutWindow( win ) ;
- if ( err ) return err ;
-
- return err ;
- }
-
-
- /**\
- |**| ==============================================================================
- |**| PRIVATE FUNCTIONS
- |**| ==============================================================================
- \**/
-
-
- /*------------------------------------------------------------------------------*\
- DoCreateAboutWindow
- *------------------------------------------------------------------------------*
- This routine actually creates the WindowRef for a winHandle.
- After creating the window, it:
- reference the window and the DocumentRecord to each other,
- makes the window the current port,
- makes it visible .
- This routine is called by:
- winOpenAbout() which fills in the winHandle structure
- \*------------------------------------------------------------------------------*/
- static OSErr DoCreateAboutWindow ( winHandle win )
- {
-
- OSErr err = noErr ;
- WindowRef window ;
-
- window = GetNewCWindow(rAboutDocWindID, nil, (WindowRef)-1 ) ;
-
- SetWinWindow( win, window ) ; // save a reference to the window in the winRecord
- SetWindowWinHandle( window, win ) ; // save a reference to the winRecord in the window
-
- SetGWorld( (CGrafPtr)GetWinWindow(win), nil ) ; // set the window to be the current port
-
- SetWinRect( win, ((CGrafPtr)window)->portRect ) ;
-
- // make sure it is visible
- ShowWindow( window ) ;
-
- return err ;
- }
-
-
-